package com.simple.utils;

import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyStringUtils {
	
	private static final Logger log = LoggerFactory.getLogger(MyStringUtils.class);
	
	//字符串转int数组
	public static int[] StringArrayToInt(String ids) {
		String array[]=ids.split(",");
		int[] intArray=new int[array.length];
		for (int i = 0; i < array.length; i++) {
			intArray[i]=Integer.parseInt(array[i]);
		}
		log.info("int数组"+Arrays.toString(intArray));
		return intArray;
	}
	
	/**
	 * 数据库名改实体名
	 * lowerName 格式sys_note 
	 * capital 是否改大写
	 * */
	public static String lowerNameToEntity(String lowerName,boolean capital) {
		if (lowerName == null)
			return lowerName;
		
		if(capital) {
			char[] chat = lowerName.toCharArray();
			if(chat[0] >= 'a' && chat[0] <= 'z'){
				chat[0] = (char)(chat[0] - 32);
			}
			lowerName=new String(chat);
		}
		
		if (lowerName.contains("_")) {
			char[] ch = lowerName.toCharArray();
			for (int index = 0; index < ch.length; index++) {
				if (ch[index] == '_' && index > 0 && index < ch.length - 1) {
					if (ch[index + 1] >= 'a' && ch[index + 1] <= 'z') {
						ch[index + 1] = (char) (ch[index + 1] - 32);
					}
				}
			}
			return new String(ch).replace("_", "");
		}
		return lowerName;
	}
	//字符串逗号处理
	public static String commaString(StringBuffer stringBuffer) {
		if(stringBuffer.length()==0) {
			return "";
		}else {
			return stringBuffer.substring(0, stringBuffer.length()-1);
		}
	}
	public static void main(String[] args) {
		System.out.println(MyStringUtils.lowerNameToEntity("sys_user", false));//sysUser
		System.out.println(commaString(new StringBuffer("String typeName,String createUser,")));
		System.out.println(commaString(new StringBuffer("String typeName,")));
		System.out.println("--"+commaString(new StringBuffer()));
		
	}
	
	
}
